{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2b94bc69-87d8-4e7a-867a-f36294dc5aef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入系数a：    4\n",
      "请输入系数b：    3\n",
      "请输入系数c：    3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "此方程有两个不等虚根： -0.375+0.7806247497997998i 和 -0.375-0.7806247497997998i  \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "a=float(input(\"请输入系数a：   \"))\n",
    "b=float(input(\"请输入系数b：   \"))\n",
    "c=float(input(\"请输入系数c：   \"))\n",
    "if (a == 0):\n",
    "    if (b == 0):print(\"此方程无解！\")\n",
    "    else:print(str.format(\"此方程的解为： {0}\", -c / b))\n",
    "else:\n",
    "    delta = b * b - 4 * a * c\n",
    "    if (delta > 0):\n",
    "        x1 = (-b + math.sqrt(delta)) / (2 * a)\n",
    "        x2 = (-b - math.sqrt(delta)) / (2 * a)\n",
    "        print(str.format(\"此方程有两个不等实根： {0} 和 {1} \", x1, x2))\n",
    "    else:\n",
    "        if (delta == 0): print(str.format(\"此方程有两个相等实根： {0}\", -b / (2 * a)))\n",
    "        else:\n",
    "            realPart = -b / (2 * a)\n",
    "            imagPart = math.sqrt(-delta) / (2 * a)\n",
    "            print(str.format(\"此方程有两个不等虚根： {0}+{1}i 和 {0}-{1}i  \", realPart, imagPart))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a77c5a1b-85d3-45e3-be4e-5fc60e248b4c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
